package xq.gwt.ui.crud;


import xq.gwt.ui.widgets.property.LabelPropertyPresenter;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.toolbar.ToolStrip;

public class PagerPresenter {
	private PagerModel pagerModel;
	private ToolStrip toolstrip;
	private PagerButtonPresenter moveFirst = new PagerButtonPresenter();
	private PagerButtonPresenter movePrevious = new PagerButtonPresenter();
	private PagerButtonPresenter moveNext = new PagerButtonPresenter();
	private PagerButtonPresenter moveLast = new PagerButtonPresenter();
	private LabelPropertyPresenter pageInfo = new LabelPropertyPresenter();
	

	public PagerPresenter(){
		toolstrip = new ToolStrip();
		LayoutSpacer spacer = new LayoutSpacer();  
		spacer.setWidth("*");
		toolstrip.setMembers(spacer,moveFirst.getButton(), movePrevious.getButton(), pageInfo.getCanvas(),moveNext.getButton(), moveLast.getButton());		
	}
	
	public PagerModel getPagerModel() {
		return pagerModel;
	}

	public void setPagerModel(PagerModel pagerModel) {
		this.pagerModel = pagerModel;
		if(this.pagerModel != null){
			moveFirst.setModel(pagerModel.getMoveFirstCommand());
			movePrevious.setModel(pagerModel.getMovePreviousCommand());
			moveNext.setModel(pagerModel.getMoveNextCommand());
			moveLast.setModel(pagerModel.getMoveLastCommand());
			pageInfo.setModel(pagerModel.getPageInfo());
		}		
	}
	
	public Canvas getCanvas(){
		return toolstrip;
	}
	
	
}
